<?php

namespace App\Models;

use App\Models\Traits\BrokeragesTrait;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Brokerage
 *
 * @property int $id
 * @property int $user_id
 * @property int $order_id
 * @property int $product_id
 * @property int $product_sku_id
 * @property string $value
 * @property string $percent
 * @property int $up_star_level
 * @property string|null $settled_at
 * @property string|null $remark
 * @property string|null $reason
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \App\Models\Order $order
 * @property-read \App\Models\Product $product
 * @property-read \App\Models\ProductSku $sku
 * @property-read \App\Models\User $user
 * @method static \Database\Factories\BrokerageFactory factory(...$parameters)
 * @method static \Illuminate\Database\Eloquent\Builder|Brokerage newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Brokerage newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Brokerage query()
 * @method static \Illuminate\Database\Eloquent\Builder|Brokerage whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Brokerage whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Brokerage whereOrderId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Brokerage wherePercent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Brokerage whereProductId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Brokerage whereProductSkuId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Brokerage whereReason($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Brokerage whereRemark($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Brokerage whereSettledAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Brokerage whereUpStarLevel($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Brokerage whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Brokerage whereUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Brokerage whereValue($value)
 * @mixin \Eloquent
 * @property string|null $disabled_at order cancelled or refunded
 * @method static \Illuminate\Database\Eloquent\Builder|Brokerage whereDisabledAt($value)
 * @method static Builder|Brokerage disabled()
 * @method static Builder|Brokerage settled()
 */
class Brokerage extends Model
{
    use BrokeragesTrait;
    use HasFactory;
    
    protected $guarded = ['id'];
    
    protected $dates = [
    	'settled_at'
    ];
	
	public function scopeSettled(Builder $builder)
	{
		return $builder->whereNotNull('settled_at');
	}
	
	public function scopeDisabled(Builder $builder)
	{
		return $builder->whereNotNull('disabled_at');
	}
    
    public function user()
    {
    	return $this->belongsTo(User::class);
    }
    
    public function order()
    {
    	return $this->belongsTo(Order::class);
    }
    
    public function product()
    {
    	return $this->belongsTo(Product::class);
    }
    
    public function sku()
    {
    	return $this->belongsTo(ProductSku::class);
    }
}
